package com.example.zkweixiu.app.activity;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;


import com.example.zkweixiu.app.MainActivity;
import com.example.zkweixiu.app.R;
import com.example.zkweixiu.app.bean.UserBean;
import com.example.zkweixiu.app.pro.PublicPro;
import com.example.zkweixiu.app.utils.SPUtils;
import com.google.gson.Gson;
import com.yanzhenjie.sofia.Sofia;

public class StartActivity extends AppCompatActivity {

    @SuppressLint("HandlerLeak")
    private Handler handler = new Handler(){
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            switch (msg.what){
                case 200:
                    UserBean loginBean = new Gson().fromJson(user, UserBean.class);
                    PublicPro.userBean = loginBean;
/*                    PublicPro.UserMap.clear();
                    PublicPro.UserMap.put("user", loginBean);*/
                    Intent intent2 = new Intent(StartActivity.this, MainActivity.class);
                    startActivity(intent2);
                    finish();
                    break;

                case 300:
                    Intent intent3 = new Intent(StartActivity.this, LoginActivity.class);
                    startActivity(intent3);
                    finish();

                    break;
            }
        }
    };
    private String user;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_start);
        Sofia.with(StartActivity.this).statusBarDarkFont().statusBarBackground(Color.parseColor("#FFFFFF"));
        user = (String) SPUtils.get(this, "user","-1");

        if ("-1".equals(user)){

            handler.sendEmptyMessageDelayed(300,1500);
        }else {
            try {

                handler.sendEmptyMessageDelayed(200,1500);

            }catch (Exception e){
                e.printStackTrace();
                Toast.makeText(this, "状态过期 重新登录", Toast.LENGTH_SHORT).show();
                Intent intent2 = new Intent(StartActivity.this, LoginActivity.class);
                startActivity(intent2);
                finish();
            }
        }
    }

    @Override
    protected void onResume() {
        super.onResume();

    }
}
